import { notify } from '@/widgets'
import { selectEntityIdByType, showEntityTablePartial } from '../table'
import { getAirportRoutingSet, getWaypointRoutingSet } from './routing-index'
import { type Routing } from './types'

export function showWaypointRoutingTable(wpt: string) {
  const routings = getWaypointRoutingSet(wpt)
  if (!routings || routings.size === 0) {
    notify.info({ content: `航路点${wpt}没有对应飞行路线!` })
    return
  }
  showEntityTablePartial<Routing>({
    key: `@@routing-by-wpt-${wpt}`,
    type: 'Routing',
    data: () => [...routings],
    name: `航路点对应飞行路线 | ${wpt} (${routings.size})`
  })
}

export function selectAndShowWaypointRoutingTable() {
  selectEntityIdByType('Waypoint', showWaypointRoutingTable)
}

export function showAirportRoutingTable(apt: string) {
  const routings = getAirportRoutingSet(apt)
  if (!routings || routings.size === 0) {
    notify.info({ content: `机场${apt}没有对应飞行路线!` })
    return
  }
  showEntityTablePartial<Routing>({
    key: `@@routing-by-apt-${apt}`,
    type: 'Routing',
    data: () => [...routings],
    name: `机场对应飞行路线 | ${apt} (${routings.size})`
  })
}

export function selectAndShowAirportRoutingTable() {
  selectEntityIdByType('Airport', showAirportRoutingTable)
}
